﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OxyPlotTest
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
       
        System.Threading.Thread mThread;
        private bool mIsStop = false;
        private MainViewModel mMainViewModel;
        private MainViewModel mMainViewModel2;
        public MainWindow()
        {
            InitializeComponent();
            //_viewModel = new PlotViewModel();
            ////画直线

            mMainViewModel = new MainViewModel(31);
            mMainViewModel2 = new MainViewModel(60);


            mThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(GetData));
            mThread.Start();
        }

        void GetData(object obj)
        {
            int nStartSeed = 50;
            while (mIsStop == false)
            {
                nStartSeed = nStartSeed + 30;
                if (nStartSeed > 100)
                    nStartSeed = 100;



                Dispatcher.Invoke(new Action(() =>
                {

                    mMainViewModel.Refresh(nStartSeed);
                    myLineSeries.DataContext = mMainViewModel;

                    mMainViewModel2.Refresh(nStartSeed + 5);
                    myLineSeries2.DataContext = mMainViewModel2;

                    myPlot.InvalidatePlot(true);

                }), null);

                System.Threading.Thread.Sleep(1000);

            }
        }

        private void Window_Closed_1(object sender, EventArgs e)
        {
            mIsStop = true;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            TestOxyPlot testOxyPlot = new TestOxyPlot();
            testOxyPlot.Show();
        }

        private void btnTimeSpanAxis_Click(object sender, RoutedEventArgs e)
        {
            TestTimeSpanAxis testTimeSpanAxis = new TestTimeSpanAxis();
            testTimeSpanAxis.Show();
        }

    }
}
